//可以完全按照js标准编写代码
const hello=(name:string) =>{
    console.log(`hello,${name}`)
}
hello('typescript')

const a:string='footer'
const b:number=100
const c:boolean=true
//const d:boolean=null//严格模式下会报错
const e:void=undefined//非严格式下可以为null
const f:null=null
const g:undefined=undefined
const h:symbol=Symbol();//es6特性在es5标准中会报错

//作用域问题
(function(){
    const a=123;
})()
export {}//使用export确保与其它示例没有成员冲突

//Object类型
const foo:object=function(){}//[]//{}
const obj:{foo:number,bar:string}={foo:132,bar:'string'}//限制对象只能有指定的成员

//数组类型
const arr1:Array<number>=[1,2,3]
const arr2:number[]=[1,2,3]

function sum(...args:number[]){
    return args.reduce((prev,current)=>prev+current,0)
}

//元组类型

//枚举类型

// enum PostStatus{
//     Draft=0,
//     Unpublished=1,
//     Published=2
// }
//可以只指定第一个值,后面的值会增加
// enum PostStatus{
//     Draft=6,
//     Unpublished,
//     Published
// } 
// enum PostStatus{
//     Draft='aaa',
//     Unpublished,
//     Published
// } 

//加上const后编译会把枚举类型去掉，并把用到枚举的地方替换成对应的值，还会在后面注释上枚举的键
const enum  PostStatus{
    Draft=6,
    Unpublished,
    Published
} 
const post={
    title:'Hello TypeScript',
    content:'sdfsdf',
    status:PostStatus.Draft
}

//函数类型
function func1(a:number,b:number):string{
    return "aaa"
}

//函数表达式
const func2: (a: number, b: number) => string=function(a:number,b:number):string{
    return 'func2'
}

//接口
interface Post{
    title:string;
    content:string;
}
function printPost(post:Post){
    console.log(post.title);
    console.log(post.content);
}
printPost({
    title:'Hello TypeScript',
    content:'aaaa'
})

//动态成员

interface Cache{
    [Prop:string]:string
}
const cache:Cache={}
cache.foo="value"
cache.bar="string"

//类
class Person{
    public name:string
    private age:number
    protected readonly gender:boolean//只读属性
    constructor(name:string,age:number){
        this.age=age
        this.name=name
        this.gender=true
    }
    sayHi(msg:string):void{
        console.log(`I am ${this.name},${msg}`)
    }
}

//new Person('gg',12).sayHi("sdfsdf")

//访问修饰符
class Student extends Person{
    private constructor (name:string,age:number){
        super(name,age)
        console.log(this.gender)
    }
    static create(name:string,age:number){
        return new Student(name,age)
    }
}
const tom=new Person('tom',18)
console.log(tom.name)
//console.log(tom.age)
//console.log(tom.gender)
const jack=Student.create('jack',22)

//泛型
function createNumberArray(length:number,value:number):number[]{
    const arr=Array<number>(length).fill(value)
    return arr
}
//const res=createNumberArray(3,100)

function createArray<T>(length:number,value:T):T[]{
    const arr=Array<T>(length).fill(value)
    return arr
}
//const res=createArray<string>(2,"100")
//import {camelCase} from 'lodash'
declare function camelCase(input:string):string
const res=camelCase('hello')